/* eslint-disable */
<template>
  <div class="list-model">
    <div class="table-box">
      <el-table
        :data="list"
        size="mini"
        style="width: 100%"
        header-cell-style="background-color: #f7f7f7;"
      >
        <el-table-column
          prop="resourceNo"
          label="编号"
          min-width="100"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.resourceNo">{{scope.row.resourceNo}}</div>
            <div v-else>/</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="productName"
          label="资源名称"
          min-width="100"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.resourceNo">{{scope.row.productName}}</div>
            <div v-else>/</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="productSource"
          label="来源"
          min-width="100"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.resourceNo">{{scope.row.productSource===1?'个人':scope.row.productSource===2?'企业':'平台'}}</span>
            <div v-else>/</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="queueName"
          label="规格"
          min-width="180"
        >
          <template slot-scope="scope">

            <div
              v-if="scope.row.resourceNo"
              class="specification"
            >
              <p>内存:{{`${toGB(scope.row.memory)}GB`}}</p>
              <!-- <p>操作系统:{{scope.row.queueName}}</p> -->
              <p>CPU:{{`${scope.row.vCpu||'--'}核`}}</p>
              <p>IP地址 :{{scope.row.host||'--'}}</p>
            </div>
            <div v-else>/</div>
            <!-- <div class="specification">
              <p>GPU:{{`${toGB(scope.row.memory)}GB`}}</p>
            </div> -->

          </template>
        </el-table-column>
        <el-table-column
          prop="price"
          label="单价（元/分钟）"
          min-width="100"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.resourceNo">{{scope.row.price}}</div>
            <div v-else>/</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="billRule"
          label="计费规则"
          min-width="100"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.resourceNo">{{scope.row.billRule===1?'梯度计费':'标准计费'}}</span>
            <div v-else>/</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="queueName"
          label="计费类型"
          min-width="100"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.resourceNo">{{scope.row.billType===0?'按量计费':'--'}}</span>
            <div v-else>/</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="queueName"
          label="时长"
          min-width="100"
        >
          <template slot-scope="scope">
            <span
              v-if="scope.row.resourceNo"
              v-html="getFormatTime(scope.row.time)"
            ></span>
            <div v-else>/</div>
          </template>
        </el-table-column>
        <!-- <el-table-column
          prop="resourceUsage"
          label="资源使用率"
          min-width="100"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.resourceNo">{{scope.row.resourceUsage||0}}%</span>
            <div v-else>/</div>
          </template>
        </el-table-column> -->
        <el-table-column
          label="起止时间"
          min-width="140"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.resourceNo">
              <div>{{scope.row.startTime||'--'}}</div>
              <div>至{{scope.row.endTime||'--'}}</div>
            </div>
            <div v-else>/</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="taskStatus"
          label="运行状态"
          min-width="100"
        >
          <template slot-scope="scope">
            <span>{{scope.row.taskStatus===1?'成功':scope.row.taskStatus===2?'失败':'运行中'}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="amount"
          label="应付金额（元）"
          min-width="100"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.resourceNo">{{scope.row.amount||0}}</span>
            <div v-else>/</div>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
  import { mapActions } from 'vuex'
  export default {
    name: 'tenement-list',
    data () {
      return {
        list: []
      }
    },
    props: {
      tenementList: Array,
      pageNo: Number,
      pageSize: Number
    },
    methods: {
      ...mapActions('security', ['deleteQueue']),
      toGB (count) {
        return (count / 1024 / 1024 / 1024).toFixed(1) || 0
      },
      /* time是秒 */
      getFormatTime (time) {
        if (!time) {
          return '<span class="m-orange">0</span>天<span class="m-orange">0</span>时<span class="m-orange">0</span>分<span class="m-orange">0</span>秒'
        }
        if (time === 0) {
          return '<span class="m-orange">0</span>天<span class="m-orange">0</span>时<span class="m-orange">0</span>分<span class="m-orange">0</span>秒'
        }
        if (typeof time === 'string') {
          // 判断传入的是不是string类型，如果是的话，先转换成时间number类型
          time = Number(time)
        }
        let oneDay = 60 * 60 * 24
        let oneHour = 60 * 60
        let oneMinute = 60
        let oneSecond = 1
        let days = 0
        let hours = 0
        let minutes = 0
        let seconds = 0
        if (time >= oneDay) {
          days = Math.floor(time / oneDay)
          hours = Math.floor((time % oneDay) / oneHour)
          minutes = Math.floor((time % oneHour) / oneMinute)
        } else if (oneHour <= time && time < oneDay) {
          hours = Math.floor(time / oneHour)
          minutes = Math.floor((time % oneHour) / oneMinute)
          seconds = Math.floor(((time % oneHour) % oneMinute) / oneSecond)
        } else if (time >= oneMinute && time < oneHour) {
          minutes = Math.floor(time / oneMinute)
          seconds = Math.floor((time - minutes * oneMinute) / oneSecond)
        } else if (time >= oneSecond && time < oneMinute) {
          seconds = Math.floor(time / oneSecond)
        }
        time = `<span class="m-orange">${days}</span>天<span class="m-orange">${hours}</span>时<span class="m-orange">${minutes}</span>分<span class="m-orange">${seconds}</span>秒`
        return time
      },
    },
    watch: {
      tenementList (a) {
        this.list = []
        setTimeout(() => {
          this.list = a
        })
      }
    },
    created () {
      this.list = this.tenementList
    }
  }
</script>

<style lang="scss"  scoped>
.table-box {
  padding-left: 10px;
  border: none;
  // margin-bottom: 20px;
}
.cli {
  // margin-left: 12px;
  font-size: 14px;
  font-family: PingFang SC, PingFang SC-Regular;
  font-weight: 400;
  text-align: LEFT;
  color: #33317e;
  line-height: 20px;
  cursor: pointer;
}
.otherCli {
  width: 10px;
  margin-left: 12px;
  font-size: 14px;
  font-family: PingFang SC, PingFang SC-Regular;
  font-weight: 400;
  text-align: LEFT;
  color: #33317e;
  // background: #fff;
  line-height: 20px;
  border: 0;
  cursor: pointer;
}
</style>
